using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/**
 * 红点结点 主要用来处理红点的逻辑。可以通过New的方式创建各个红点的逻辑处理器
 */
public class RedDotTreeNode
{

    /// <summary>
    /// 红点类型
    /// </summary>
    public RedDotType redDotType;
    /// <summary>
    /// 父节点
    /// </summary>
    public RedDotDefine parentNode;
    /// <summary>
    /// 当前节点
    /// </summary>
    public RedDotDefine node;
    /// <summary>
    /// 红点显示状态
    /// </summary>
    public bool redDotActive;
    /// <summary>
    /// 红点要显示个数
    /// </summary>
    public int redDotCount;
    /// <summary>
    /// 红点逻辑处理器
    /// </summary>
    public System.Action<RedDotTreeNode> logicHander;
    /// <summary>
    /// 红点状态改变事件 通知UI去改变红点UI
    /// </summary>
    public System.Action<RedDotType, bool, int> OnRedDotActiveChange;
    /// <summary>
    /// 刷新红点显示状态
    /// </summary>
    /// <returns></returns>
    public virtual bool RefreshRedDotState()
    {
        redDotCount = 0;
        if (redDotType== RedDotType.RedDotNodeNum)
        {
            //获取子节点显示的红点个数，去显示红点个数。
            redDotCount= RedDotSystem.Instance.GetChildNodeRedDotCount(node);
            //当前的红点是否显示: 前提是需要当前的子节点红点个数大于0(包括自身)
            redDotActive = redDotCount > 0;
        }
        else
        {
            redDotCount = RefreshRedDotCont();
        }

        logicHander?.Invoke(this);

        if (redDotType== RedDotType.RedDotDataNum)
            redDotActive= redDotCount > 0;
        
        //刷新时UI层会同步红点状态的显示
        OnRedDotActiveChange?.Invoke(redDotType,redDotActive,redDotCount);

        return redDotActive;
    }
    /// <summary>
    /// 刷新红点个数
    /// </summary>
    /// <returns></returns>
    public virtual int RefreshRedDotCont()
    {
        return 1;
    }
}